package com.qf.java2207.no3_teamproject_springboot_01.service.impl;
//须知少时凌云志，曾许人间第一流

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.qf.java2207.no3_teamproject_springboot_01.mapper.SecurityEquipmentMapper;
import com.qf.java2207.no3_teamproject_springboot_01.pojo.SecurityEquipment;
import com.qf.java2207.no3_teamproject_springboot_01.service.SecurityEquipmentService;
import com.qf.java2207.no3_teamproject_springboot_01.vo.LayuiPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SecurityEquipmentServiceImpl implements SecurityEquipmentService {

    @Autowired
    private SecurityEquipmentMapper securityEquipmentMapper;


    @Override
    public LayuiPageVo<SecurityEquipment> securityEquipmentPageData(Map<String, Object> params) {
        // mybatis 的 分页插件
        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params.get("limit")+"");
        PageHelper.startPage(page,limit);

        List<SecurityEquipment> securityEquipments = securityEquipmentMapper.selectByParams(params);

        // mybatis 的 分页数据结构
        PageInfo<SecurityEquipment> securityEquipmentPageInfo = new PageInfo<>(securityEquipments);
        //把mybatis 的 分页数据 封装到  layui 的分页数据结构中

        LayuiPageVo<SecurityEquipment> securityEquipmentLayuiPageVo = new LayuiPageVo<>();
        securityEquipmentLayuiPageVo.setCode(0);  // layui 默认 0 是正确的状态码
        securityEquipmentLayuiPageVo.setMsg("分页列表数据"); // 提示信息
        securityEquipmentLayuiPageVo.setCount(securityEquipmentPageInfo.getTotal()); // 总记录数
        securityEquipmentLayuiPageVo.setData(securityEquipmentPageInfo.getList());  // 分页的列表数据
        return securityEquipmentLayuiPageVo;
    }

//    @Override
//    public List<SecurityEquipment> securityEquipmentsList() {
//        return securityEquipmentMapper.selectByExample(null);
//    }


    @Override
    public int deleteSecurityEquipment(Integer id) {
        return securityEquipmentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateSecurityEquipment(SecurityEquipment securityEquipment) {

        int i = securityEquipmentMapper.updateByPrimaryKeySelective(securityEquipment);

        return i;
    }

    @Override
    public int addSecurityEquipment(SecurityEquipment securityEquipment) {
        int i = securityEquipmentMapper.insertSelective(securityEquipment);
        return i;
    }

}
